export default {
	methods: {
		async repairFaultInfoListAsync(faultyGroup, filterId = "ggd_defectcode") {
			let uPhone = this.UserInfo.mobile;
			let token = this.UserInfo.RetId;
			let orderDetailId = this.orderDetailId;
			let {
				RetBool,
				RetObject,
				RetMsg
			} = await this.workordercompleteservice
				.RepairFaultInfoListAsync(uPhone, orderDetailId, filterId, faultyGroup, token)
			if (RetBool) {
				//console.log(JSON.parse(RetObject))
				return RetObject ? JSON.parse(RetObject) : []
			} else
				throw RetMsg || "api出错"
		},

		async productInfoAsync() {
			let uPhone = this.UserInfo.mobile;
			let token = this.UserInfo.RetId;
			let prouctId = this.prodItemObj.ProuctId;
			let {
				RetBool,
				RetObject,
				RetMsg
			} = await this.workordercompleteservice
				.ProductInfoAsync(uPhone, prouctId, token);
			if (RetBool) {
				if (RetObject) {
					let prodInfoArray = JSON.parse(RetObject)
					return prodInfoArray[0] || []
				} else {
					return {}
				}
			} else
				throw RetMsg || "api出错"
		},
		
		async ApplySpecialWarrantyReasonCodeListAsync() {
			let uPhone = this.UserInfo.mobile;
			let token = this.UserInfo.RetId;
			let {
				RetBool,
				RetObject,
				RetMsg
			} = await this.workordercompleteservice.ApplySpecialWarrantyReasonCodeListAsync(uPhone, token);
			if (RetBool) {
				if (RetObject) {
					let data = JSON.parse(RetObject)
					return data;
				} else {
					return {}
				}
			} else
				throw RetMsg || "api出错"
		},
		
		async ExcludeFromWarrantyReasonCodeListAsync() {
			let uPhone = this.UserInfo.mobile;
			let token = this.UserInfo.RetId;
			let {
				RetBool,
				RetObject,
				RetMsg
			} = await this.workordercompleteservice.ExcludeFromWarrantyReasonCodeListAsync(uPhone, token);
			if (RetBool) {
				if (RetObject) {
					let data = JSON.parse(RetObject)
					return data;
				} else {
					return {}
				}
			} else
				throw RetMsg || "api出错"
		},
		
		async RepairSearchNewPartAsync(partsKeyWord){
			let uPhone = this.UserInfo.mobile;
			let token = this.UserInfo.RetId;
			let custProductGuid = this.prodItemObj.proCustProdID;
			let productGuid = this.prodItemObj.ProuctId;
			let custProductPurchaseDate = this.prodItemObj.PurchaseDate;
			let isCustProductConfirmed = this.prodItemObj.IsProductConfirmed;
			let WOGUID = this.orderDetailId;
			let {
				RetBool,
				RetObject,
				RetMsg
			} = await this.workordercompleteservice
				.RepairSearchNewPartAsync(uPhone, custProductGuid, productGuid,
					custProductPurchaseDate, isCustProductConfirmed, partsKeyWord, WOGUID,token)
			if (RetBool) {
				//console.log(JSON.parse(RetObject))
				return RetObject? JSON.parse(RetObject) : []
			} else
				throw RetMsg || "api出错"
		},
		async GetPagePartImg(subAccessorieList) {
			let imageArray = new Array();
			for (let accessorIndex in subAccessorieList) {
				let ImgId = subAccessorieList[accessorIndex].ImgId;
				if (ImgId) {
					imageArray.push(ImgId)
				}
			}
			let imageids = imageArray.join(",");
			let imgresult = await this.GetPartImg(imageids);
		
			for (let imgindex in imgresult) {
				let accessList = subAccessorieList.filter(accessItem => {
					return imgresult[imgindex].ImgId === accessItem.ImgId
				});
				if (accessList.length > 0) {
					for (let accessIndex in accessList)
						accessList[accessIndex].base64Img = `data:image/jpeg;base64,${imgresult[imgindex].ImgBaseStr}`;
				}
			}
		},
		
	    async GetPartImg(imageIds) {
	    	if (imageIds.length > 0) {
	    		let uPhone = this.UserInfo.mobile;
	    		let token = this.UserInfo.RetId;
	    		let result = await this.commService.ImageReaderAsync(uPhone, imageIds, 1, token);
	    		if (result.RetBool && result.RetObject) {
	    			return JSON.parse(result.RetObject)
	    		}
	    		return [] ;
	    	}
	    	return []
	    },
		getImageBase64(itempic) {
			let srcbase64 = `data:image/${itempic.FileType.replace('.','')};base64,${itempic.ImageContent}`;
			return srcbase64;
		},
		
		
	}
}
